package com.example.feifei.newproject;

import android.annotation.TargetApi;
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.Color;
import android.os.Build;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.MotionEvent;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;

import com.example.feifei.mvp.view.LoginActivity;
import com.example.feifei.mvvm.view.MvvmActivity;
import com.example.feifei.utils.SystemBarTintManager;

public class MainActivity extends AppCompatActivity  implements View.OnClickListener{

    private Button btn_coordinator;
    private Button btn_recycleview;
    private Button btn_scrollview;
    private Button btn_chatdemo;
    private Button btn_layoutflower;
    private Button btn_myview;
    private Button layout_pager_scroll;
    private Button btn_customView;
    private Button btn_nfc;
    private Button btn_bankScan;
    private Button btn_mvpTest;
    private Button btn_mvvmTest;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
//        this.requestWindowFeature(Window.FEATURE_NO_TITLE);
        supportRequestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.activity_main);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
            setTranslucentStatus(true);
            SystemBarTintManager tintManager = new SystemBarTintManager(this);
            tintManager.setStatusBarTintEnabled(true);
            tintManager.setStatusBarTintResource(R.color.colorAccent);//状态栏所需颜色
        }
        initView();
    }

    private void initView(){
        btn_coordinator = (Button) this.findViewById(R.id.btn_coordinator);
        btn_coordinator.setOnClickListener(this);
        btn_recycleview = (Button) this.findViewById(R.id.btn_recycleview);
        btn_recycleview.setOnClickListener(this);
        btn_scrollview = (Button) this.findViewById(R.id.btn_scrollview);
        btn_scrollview.setOnClickListener(this);
        btn_chatdemo = (Button) this.findViewById(R.id.btn_chatdemo);
        btn_chatdemo.setOnClickListener(this);
        btn_layoutflower = (Button) this.findViewById(R.id.btn_layoutflower);
        btn_layoutflower.setOnClickListener(this);
        btn_myview = (Button) this.findViewById(R.id.btn_myview);
        btn_myview.setOnClickListener(this);
        layout_pager_scroll = (Button) this.findViewById(R.id.layout_pager_scroll);
        layout_pager_scroll.setOnClickListener(this);
        btn_customView = (Button) this.findViewById(R.id.btn_customView);
        btn_customView.setOnClickListener(this);
        btn_nfc = (Button) this.findViewById(R.id.btn_nfc);
        btn_nfc.setOnClickListener(this);
        btn_bankScan = (Button) this.findViewById(R.id.btn_bankScan);
        btn_bankScan.setOnClickListener(this);
        btn_mvpTest = (Button) this.findViewById(R.id.btn_mvpTest);
        btn_mvpTest.setOnClickListener(this);
        btn_mvvmTest = (Button) this.findViewById(R.id.btn_mvvmTest);
        btn_mvvmTest.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            //布局使用练习
            case R.id.btn_coordinator:
                Intent intent_coordinator = new Intent(MainActivity.this,CoordinatorActivity.class);
                startActivity(intent_coordinator);
                break;
            //RecycleView的联系使用
            case R.id.btn_recycleview:
                Intent intent_recycler = new Intent(MainActivity.this,RecycleViewActivity.class);
                startActivity(intent_recycler);
                break;
            //ScrollView布局判断
            case R.id.btn_scrollview:
                Intent intent_scroll = new Intent(MainActivity.this,ScrollViewActivity.class);
                startActivity(intent_scroll);
                break;
            //部分组件测试
            case R.id.btn_chatdemo:
                Intent intent_chat = new Intent(MainActivity.this,ChatDemoActivity.class);
                startActivity(intent_chat);
                break;
            //布局散花测试
            case R.id.btn_layoutflower:
                Intent intent_flower = new Intent(MainActivity.this,FlowerLayoutActivity.class);
                startActivity(intent_flower);
                break;
            //属性动画练习
            case R.id.btn_myview:
                Intent intent_myview  = new Intent(MainActivity.this,MyViewActivity.class);
                startActivity(intent_myview);
                break;
            //Viewpager滑动监听
            case R.id.layout_pager_scroll:
                Intent intent_pager = new Intent(MainActivity.this,PagerActivity.class);
                startActivity(intent_pager);
                break;
            //自定义组件联系
            case R.id.btn_customView:
                Intent intent_custom = new Intent(MainActivity.this,CustomViewActivity.class);
                startActivity(intent_custom);
                break;
            //NFC功能开发
            case R.id.btn_nfc:
                Intent intent_nfc = new Intent(MainActivity.this,NFCFuctionActivity.class);
                startActivity(intent_nfc);
                break;
                //银行卡扫描识别
            case R.id.btn_bankScan:
                Intent intent_bank = new Intent(MainActivity.this,BankScanActivity.class);
                startActivity(intent_bank);
                break;
                //MVP模式测试
            case R.id.btn_mvpTest:
                Intent intent_mvp = new Intent(MainActivity.this, LoginActivity.class);
                startActivity(intent_mvp);
                break;
                //MVVM模式测试
            case R.id.btn_mvvmTest:
                Intent intent_mvvm = new Intent(MainActivity.this, MvvmActivity.class);
                startActivity(intent_mvvm);
                break;
        }

    }

    /*
    * 沉浸式布局
    */
    @TargetApi(19)
    private void setTranslucentStatus(boolean on) {
        Window win = getWindow();
        WindowManager.LayoutParams winParams = win.getAttributes();
        final int bits = WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS;
        if (on) {
            winParams.flags |= bits;
        } else {
            winParams.flags &= ~bits;
        }
        win.setAttributes(winParams);
    }

}
